//
//  MenuViewController.m
//  QuanNengSaoMiaoZhuShou
//
//  Created by lanou3g on 16/3/10.
//  Copyright © 2016年 于博文. All rights reserved.
//

#import "MenuViewController.h"
#import "MyDocument_ViewController.h"
#import "Set_ViewController.h"
#import "HelpBook_ViewController.h"

@interface MenuViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) UITableView *RootTableView;

@end
static NSString *const registActivity = @"regist";
static NSString *const registHearder = @"resgistHearder";
@implementation MenuViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self setRootTableView];
    self.view.backgroundColor = kTintColor;
    self.RootTableView.backgroundColor = kTintColor;
    
}
#pragma mark ----------------设置tableView--------------
- (void)setRootTableView {
    self.RootTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCreamWidth, kSCreamHeight) style:(UITableViewStylePlain)];
    _RootTableView.delegate = self;
    _RootTableView.dataSource = self;
    [self.view addSubview:_RootTableView];
    [_RootTableView registerNib:[UINib nibWithNibName:@"MenuTableViewCell" bundle:nil] forCellReuseIdentifier:registActivity];
    [_RootTableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:registHearder];
    _RootTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  
  }
#pragma mark --------------懒加载---------------
//点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //选择菜单是触发的变化
    [self SelectActionForUserSetting:indexPath];
    switch (indexPath.section) {
        case 0:{
            switch (indexPath.row) {
                case 0:
                {
                    LoginViewController * loginVC = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
                    [self set_RootViewController:loginVC title:@"登录"];

                    break;
                }
                case 1:
                {
                    RootViewController *RootCV = [RootViewController new];
                    [self set_RootViewController:RootCV title:@"我的文档"];
                    break;
                }
                case 2:
                {
                    Set_ViewController *setVC = [[Set_ViewController alloc]initWithNibName:@"Set_ViewController" bundle:nil];
                    [self set_RootViewController:setVC title:@"设置"];;
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 1:{
            switch (indexPath.row) {
                case 0:
                {
                    HelpBook_ViewController *helpBook = [[HelpBook_ViewController alloc]initWithNibName:@"HelpBook_ViewController" bundle:nil];
                    [self set_RootViewController:helpBook title:@"帮助手册"];
                    break;
                }
                case 1:
                {
                    HelpBook_ViewController *helpBook = [[HelpBook_ViewController alloc]initWithNibName:@"HelpBook_ViewController" bundle:nil];
                    [self set_RootViewController:helpBook title:@"新手必看"];
                    break;
                }
                default:
                    break;
            }
            break;
        }
            
        default:
            break;
    }
}
//设置区头视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kSCreamHeight*23/100)];
    headerView.backgroundColor = kTintColor;
    return headerView;
}

////设置区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        {
            return 0;
        }
            break;
        default:
        {
            return kSCreamHeight*54/100;
        }
            break;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
        {
            return 3;
        }
            break;
            
        default:
        {
            return 2;
        }
            break;
    }

    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch(indexPath.section)
    {
        case 0:
        {
            switch(indexPath.row)
        {
            case 0:
                return kSCreamHeight*14/100;
                break;
            default:
            {
            return kSCreamHeight*9/100;
            }
        }
            break;
        }
        case 1:
        {
        return kSCreamHeight*7/100;
        }
        default:{
        return 0;
        }
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:registActivity forIndexPath:indexPath];

    cell.signView.alpha = 0;
    switch (indexPath.section) {
        case 0:{
            switch (indexPath.row) {
                case 0:
                {
                    cell.title_label.text = @"登录/注册";
                    cell.title_label.font = [UIFont systemFontOfSize:27];
                     cell.imgView.image = [UIImage imageNamed:@"ic_right_menu_user_story"];
                    break;
                }
                case 1:
                {
                    cell.title_label.text = @"我的文档";
                    cell.signView.alpha = 1;
                    cell.backgroundColor = kTintColor_Dark;
                    cell.imgView.image = [UIImage imageNamed:@"fild_md"];
                    break;
                }
                case 2:
                {
                    cell.title_label.text = @"设置";
                    cell.imgView.image = [UIImage imageNamed:@"ic_capture_settings"];
                    break;
                }
                default:
                    break;
            }
            
            break;
        }
        case 1:{
            switch (indexPath.row) {
                case 0:
                {
                    cell.title_label.text = @"帮助手册";
                    cell.title_label.font = [UIFont systemFontOfSize:20];
                    cell.imgView.image = [UIImage imageNamed:@"circle_help_"];
                    break;
                }
                case 1:
                {
                    cell.title_label.text = @"新手必看";
                    cell.title_label.font = [UIFont systemFontOfSize:20];
                    cell.imgView.image = [UIImage imageNamed:@"ic_cc_simple_card"];
                    break;
                }

                default:
                    break;
            }
            
            break;
        }
            
        default:
            break;
    }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
   
    return cell;
}
/**
 *  cell被选择是ui做出的反应
 */
- (void)SelectActionForUserSetting:(id) sender {
    NSArray *array = [self.RootTableView indexPathsForVisibleRows];
    for (NSIndexPath *index in array) {
        MenuTableViewCell *cell = [self.RootTableView cellForRowAtIndexPath:index];
        cell.signView.alpha = 0;
        cell.backgroundColor = [UIColor clearColor];
    }
    NSIndexPath *indexPath = [self.RootTableView indexPathForSelectedRow];
    MenuTableViewCell *cell = [self.RootTableView cellForRowAtIndexPath:indexPath];
    cell.signView.alpha = 1;
    cell.backgroundColor = kTintColor_Dark;

   }

- (void)set_RootViewController:(UIViewController *)rootviewController title:(NSString *)title
{
    //设置根视图控制器
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    UINavigationController *read_na = [[UINavigationController alloc]initWithRootViewController:rootviewController];
    read_na.navigationBar.translucent = NO;
      [app.draw setRootViewController:read_na title:title];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
